package com.bawei.system;

public class Solution {
    public static int lengthOfLongestSubstring(String s) {
        int maxLength = 0;
        int start = 0;
        int[] charCount = new int[128]; // ASCII字符集大小为128

        for (int i = 0; i < s.length(); i++) {
            char currentChar = s.charAt(i);
            charCount[currentChar]++;

            while (charCount[currentChar] > 1) {
                char previousChar = s.charAt(start);
                charCount[previousChar]--;
                start++;
            }

            maxLength = Math.max(maxLength, i - start + 1);
        }

        return maxLength;
    }
    public static void main(String[] args) {
        String s = "pwwkew";
        //改bug，
        int result = lengthOfLongestSubstring(s);
        System.out.println(result);
    }
}